
function AdUi (){
	this.version = "0.0.1-SNAPSHOT";
	this.author = "skjanyou";
	this.app = Object.create([]);
	this.step = Object.create({});	
	this.startCostTime = 0;
	this.status = AdUi.status.shutdown;
	this.runtime = Object.create({});
}
AdUi.step = {
	"BeforeStart" : "BeforeStart",
	"AfterStart" : "AfterStart",
	"BeforeShutdown" : "BeforeShutdown",
	"AfterShutdown" : "AfterShutdown"
};
AdUi.status = {
	"shutdown":"shutdown",
	"booting":"booting",
	"running":"running",
};
/**
 * 
 *  
 * 
 * 
 */
AdUi.prototype = {
	startup : function(){
		this.status = AdUi.status.booting;
		
		this.runtime.screenHeight = window.screen.height;
		this.runtime.screenWidth = window.screen.width;
		
		var d1 = new Date();
		this.step[ AdUi.step.BeforeStart ] && this.step[ AdUi.step.BeforeStart ].call( this );
		
		console.log( "Os is startting ..." );
		
		this.step[ AdUi.step.AfterStart ] && this.step[ AdUi.step.AfterStart ].call( this );
		
		var d2 = new Date();
		console.log( "Os is started ..." );
		this.startCostTime = ( d1 - d2 ) / 1000;
		this.status = AdUi.status.running;
	},
	shutdown  : function(){
		this.step[ AdUi.step.BeforeShutdown ] && this.step[ AdUi.step.BeforeShutdown ].call( this );
		
		console.log( "Os is shutdown ..." );
		AdUiApp.app.forEach( function( app ){
			
			var appName = app.name;
			console.log( "%s is closing",appName );
			// send message to app 
			app[ AdUiApp.step.BeforeDestroy ] && app[ AdUiApp.step.BeforeDestroy ].call( app );
			app[ AdUiApp.step.AfterDestroy ] && app[ AdUiApp.step.AfterDestroy ].call( app );
			
			app = null;
			console.log( "%s is closed", appName );
		});
		
		this.step[ AdUi.step.AfterShutdown ] && this.step[ AdUi.step.AfterShutdown ].call( this );
		this.status = AdUi.status.shutdown;
	},
	on : function( step, callback ){
		AdUi.step[ step ] && ( this.step[ step ] = callback );
	},
	installApp : function( app , alias ){
		// use alias
		alias && ( app.name = alias );
		this.app.push( app );
	},
	unInstallApp : function( app0 ){
		this.app.forEach( function( app,index ){
			app.appid = app0.appid ? ( this.app.splice( index, 1 ) ) : false;
		}.bind(this));
	}
};


function AdUiApp( options ){
	this.appid = options.appid;
	this.title = options.title;
	this.icon = options.icon;
	this.status = AdUiApp.status.hide;
	this.src = options.src;
	this.init();
}
AdUiApp.app = Object.create([]);
AdUiApp.step = {
	"BeforeShow":"BeforeShow",
	"AfterShow":"AfterShow",
	"BeforeHide":"BeforeHide",
	"AfterHide":"AfterHide",
	"BeforeDestroy":"BeforeDestroy",
	"AfterDestroy":"AfterDestroy"
};
AdUiApp.status = {
	"show":"show",
	"hide":"hide"
};

/**
 *  onStart : function( AdUi, AdUiApp, message ){} 
 *  onRestart : 
 *  onPaused :
 *	onStop : 
 *  onDestroy
 * 
 */
AdUiApp.prototype = {
	init : function(){
		this.render && this.render();
	},
	show : function(){},
	hide : function(){},
};

